import 'package:bloc/bloc.dart';
import 'package:qgchat/http/apis/video.dart';
import 'package:qgchat/http/models/invitationInfoModel.dart';

class InvitationInfoBlocEvent {}

class InvitationInfoBlocBloc
    extends Bloc<InvitationInfoBlocEvent, InvitationInfoModel> {
  final int inv;

  InvitationInfoBlocBloc({this.inv}) {
    add(InvitationInfoBlocEvent());
  }

  @override
  Stream<InvitationInfoModel> mapEventToState(
    InvitationInfoBlocEvent event,
  ) async* {
    InvitationInfoModel res = await VideoApis.invitationInfo(inv);
    if (res.gold == null || res.gold == 0) {
      await Future.delayed(Duration(seconds: 1));
      res = await VideoApis.invitationInfo(inv);
    }
    yield res;
  }

  @override
  InvitationInfoModel get initialState => InvitationInfoModel();
}
